package com.atguigu.ssyx.acl.service.impl;

import com.atguigu.ssyx.acl.mapper.AdminMapper;
import com.atguigu.ssyx.acl.service.AdminService;
import com.atguigu.ssyx.model.acl.Admin;
import com.atguigu.ssyx.vo.acl.AdminQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {

    /**
     * 用户列表（条件分页查询）
     * @param page
     * @param adminQueryVo
     * @return
     */
    @Override
    public IPage<Admin> selectAdminPage(Page<Admin> page, AdminQueryVo adminQueryVo) {
        String userName = adminQueryVo.getUsername();
        String name = adminQueryVo.getName();
        // mp条件对象
        LambdaQueryWrapper<Admin> wrapper = new LambdaQueryWrapper<>();
        // 判断是否为空，不为空则进行条件查询
        if (!StringUtils.isEmpty(userName)) {
            wrapper.eq(Admin::getUsername, userName);
        }
        if (!StringUtils.isEmpty(name)) {
            wrapper.like(Admin::getName, name);
        }
        // 调用方法实现条件分页查询
        return baseMapper.selectPage(page, wrapper);
    }
}
